/*****************************************************************************
 * Copyright (C) Stacy Curl. All rights reserved.                            *
 * ------------------------------------------------------------------------- *
 * The software in this package is published under the terms of the BSD      *
 * style license a copy of which has been included with this distribution in *
 * the LICENSE.txt file.                                                     *
 *****************************************************************************/
package picounit.features.test_instantiator;

import picounit.TestFilter;

public class AggregateTestFilter implements TestFilter {
	private final TestFilter[] testFilters;

	public AggregateTestFilter(TestFilter ... testFilters) {
		this.testFilters = testFilters;
	}
	
	public boolean matches(Class testClass) {
		for (TestFilter testFilter : testFilters) {
			if (!testFilter.matches(testClass)) {
				return false;
			}
		}

		return true;
	}
	
	@Override
	public String toString() {
		StringBuilder stringBuilder = new StringBuilder("[");

		for (int index = 0; index < testFilters.length; ++index) {
			TestFilter testFilter = testFilters[index];

			stringBuilder.append(testFilter.toString());

			if (index < testFilters.length - 1) {
				stringBuilder.append(", ");
			}
		}

		return stringBuilder.append("]").toString();
	}
}
